<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<jsp:useBean class="forum.Thread" id="t" scope="page"/>
<jsp:useBean class="forum.SubForum" id="s" scope="page"/>
<c:if test="${empty param.threadID || empty param.subForumID}">
	<c:if test="${empty param.subForumID}">
		<c:redirect url="index.jsp"/>
	</c:if>
	<c:redirect url="subforum.jsp?subForumID=${param.subForumID}"/>
</c:if>
<c:set target="${t}" property="threadID" value="${param.threadID }"/>
<c:set target="${s}" property="subForumID" value="${param.subForumID}"/>
<c:set target="${t}" property="views" value="${t.views}"/>
<c:set var="posts" value="${t.posts}"/>
<c:set var="tmp" scope="page">User Moderator Administrator</c:set>
<c:set var="lvls" scope="page" value="${fn:split(tmp,' ')}"/>
<title>Thread - ${t.name}</title>
</head>
<body>

<p><small>
<a href="index.jsp" style="color:#000000;">index</a> >
<a href="subforum.jsp?subForumID=${s.subForumID}" style="color:#000000;">${s.name }</a> 
> ${t.name}</small></p>

	<td>
		<div style="float:right;margin-left:auto;margin-right:0px;">
			<%@ include file="LoginForm.jsp" %>
		</div>
		<div style="float:left;margin-left:0px;margin-right:auto;">
		<table border="0" style="width:800px">
		<c:set var="PostNr" value="1"/>
		<c:forEach var="post" items="${posts}">
			<c:choose>
				<c:when test="${param.edit eq PostNr and sessionScope.user.userID eq post.createdBy.userID}">
					<%@ include file="cePost.jsp" %>
				</c:when>
				<c:otherwise>
					<tr>
						<td>
						<table border="1" style="min-height:200px;">
						<tr>
							<td colspan = "2" bgcolor="#C0C0C0" style="height:18px;"><a id="link${PostNr}"></a>
							<div style="float:left;">${post.createdOn}</div><div style="float:right;">#${PostNr}</div>
							<c:if test="${sessionScope.user.userID eq post.createdBy.userID}">
								<div style="float:right;">
								<a href="thread.jsp?subForumID=${s.subForumID}&threadID=${t.threadID}&edit=${PostNr}#link${PostNr}" style="color:#000000">
								Edit</a>&#160;</div>
							</c:if>
							</td>
						</tr>
							<tr>
								<td width="150px" bgcolor="#E0E0E0" align = "left" valign="top">
									<nobr>${post.createdBy.name }</nobr><br>
									<small>${lvls[post.createdBy.userlvl]}<br>
									joined: ${post.createdBy.joined}<br>
									posts: ${post.createdBy.numberOfPosts}
									</small>
								</td>
								<td width="450px" align="left" valign="top" height="200px">
									${post.content }
								</td>
							</tr>
						</table>
						</td>
					</tr>
				</c:otherwise>
			</c:choose>
			<c:set var="PostNr" value="${PostNr+1}"/>
		</c:forEach>
		<c:if test="${not empty sessionScope.user }">
		<!--	<tr>
				<td>
				<table border="1" style="min-height:266px;">
				<tr>
					<td colspan = "2" bgcolor="#C0C0C0" style="height:18px;">
					<div style="float:left;">New post</div><div style="float:right;">#${PostNr}</div>
					</td>
				</tr>
					<tr>
						<td width="150px" bgcolor="#E0E0E0" align = "left" valign="top">
							<nobr>${sessionScope.user.name }</nobr><br>
							<small>${lvls[sessionScope.user.userlvl]}<br>
							joined: ${sessionScope.user.joined}<br>
							posts: ${sessionScope.user.numberOfPosts}
							</small>
						</td>
						<td width="450px" align="left" valign="top" height="266px">
							<form ACTION="ForumController" METHOD="POST" >
								<textarea id="content" name="content" 
								style="position:inherit;height:263px;width:445px;overflow:auto;font-family:Times New Roman;font-size:100%;"></textarea>
								<input type="hidden" name="action" value="makePost" READONLY>
								<input type="hidden" name="threadID" value="${param.threadID }" READONLY>
								<input type="hidden" name="subForumID" value="${param.subForumID }" READONLY>
								<br><input type="submit" value="Post!" style="position:inherit;width:450px"/>
							</form>
						</td>
					</tr>
				</table>
				</td>
			</tr>-->
			<%@ include file="cePost.jsp" %>
		</c:if>
		</table>
			<!--<c:choose>
				<c:when test="${not empty sessionScope.user}">
					Content:<br>
					<form ACTION="ForumController" METHOD="POST" style="position:absolute;left:170px">
						<textarea id="content" name="content" 
						style="height:200px;width:455px;"></textarea>
						<input type="hidden" name="action" value="makePost" READONLY>
						<input type="hidden" name="threadID" value="${param.threadID }" READONLY>
						<br><input type="submit" value="Post!" />
					</form>
			
				</c:when>
				<c:otherwise>
					<p>Login to post in this thread!</p>
				</c:otherwise>
			</c:choose>-->
		</div>
		
	</td>

</body>
</html>